﻿/******************************************************    
文件名:TableSteelDataDB.cs
版权  (c)  2010-11-23 淘渺圈圈工作室
作者:黄媛媛
创建日期:2010-12-08
维护人员:黄媛媛
维护日期:2010-12-08
文件功能描述:金属材料热处理网络学习平台_访问材料数据操作
******************************************************/
using System;
using System.Collections.Generic;
using System.Text;
using System.Data.SqlClient;
using System.Configuration;
using System.Collections;
using System.Data;

namespace Mmht.DB
{
    public class TableSteelDataDB
    {
        operate op = new operate();
        
        /// <summary>
        /// 元素种类查询
        /// </summary>
        /// <param name="table_type">数据表类型</param>
        /// <param name="table_type">1SteelComposition</param>
        /// <param name="table_type">2MaterialsNumber</param>
        /// <returns></returns>
        public DataTable get_X(int table_type)
        {
            string sql = @"select distinct x
                        from x_content
                        where table_type = " + table_type + " order by x";
            return op.Query(sql);
        }

        /// <summary>
        /// 数据表左半部分信息查询
        /// </summary>
        /// <param name="table_type">数据表类型</param>
        /// <param name="table_type">1SteelComposition</param>
        /// <param name="table_type">2MaterialsNumber</param>
        /// <returns></returns>
        public DataTable get_Tableleft(int table_type)
        {
            switch (table_type)
            {
                case 1: return get_SteelComposition();
                case 2: return get_MaterialsNumber();
                default: return null;
            }
        }
        /// <summary>
        /// 牌号及其化学成分查询
        /// </summary>
        /// <returns></returns>
        public DataTable get_SteelComposition()
        {
            string sql = @"select id,name,name_en,steel_type,code,remark
                        from steel_composition";
            return op.Query(sql);
        }

        /// <summary>
        /// 材料编号查询
        /// </summary>
        /// <returns></returns>
        public DataTable get_MaterialsNumber()
        {
            string sql = @"select id,name,number,type,remark
                        from materials_number";
            return op.Query(sql);
        }

        /// <summary>
        /// 某种牌号及化学成分具体元素含量查询
        /// </summary>
        /// <returns></returns>
        public DataTable get_XContent(int table_type,int s_id)
        {
            string sql = @"select s_id,x,x_content
                        from x_content
                        where table_type = " + table_type + " and s_id = " + s_id;
            return op.Query(sql);
        }

        /// <summary>
        /// 组织和性能数据查询
        /// </summary>
        /// <returns></returns>
        public DataTable get_StructureProperty()
        {
            string sql = @"select id,name,photo,description,size,strength,
                        elongation,reduction,hardness,test
                        from structure_property";
            return op.Query(sql);
        }

        /// <summary>
        /// 热处理数据查询
        /// </summary>
        /// <returns></returns>
        public DataTable get_HeatTreatingData()
        {
            string sql = @"select id,name,number,a1,a3,ms_mz,ttt_curve,cct_curve,
                        jominy_curve,tempering_curve,diagram,technics,remark
                        from heat_treating_data ";
            return op.Query(sql);
        }

        /// <summary>
        /// 组织和性能数据查询
        /// </summary>
        /// <returns></returns>
        public DataTable search_StructureProperty(string key)
        {
            string sql = @"select id,name,photo,description,size,strength,
                        elongation,reduction,hardness,test
                        from structure_property where name like '%" + key + "%'";
            return op.Query(sql);
        }

        /// <summary>
        /// 热处理数据查询
        /// </summary>
        /// <returns></returns>
        public DataTable search_HeatTreatingData(string key)
        {
            string sql = @"select id,name,number,a1,a3,ms_mz,ttt_curve,cct_curve,
                        jominy_curve,tempering_curve,diagram,technics,remark
                        from heat_treating_data where name like '%" + key + "%'";
            return op.Query(sql);
        }

        /// <summary>
        /// 数据表左半部分信息查询
        /// </summary>
        /// <param name="table_type">数据表类型</param>
        /// <param name="table_type">1SteelComposition</param>
        /// <param name="table_type">2MaterialsNumber</param>
        /// <returns></returns>
        public DataTable search_Tableleft(string table_name,string key)
        {
            switch (table_name)
            {
                case "steel_composition": return search_SteelComposition(key);
                case "materials_number": return search_MaterialsNumber(key);
                default: return null;
            }
        }
        /// <summary>
        /// 牌号及其化学成分查询
        /// </summary>
        /// <returns></returns>
        public DataTable search_SteelComposition(string key)
        {
            string sql = @"select id,name,name_en,steel_type,code,remark
                        from steel_composition where name like '%" + key + "%'";
            return op.Query(sql);
        }

        /// <summary>
        /// 材料编号查询
        /// </summary>
        /// <returns></returns>
        public DataTable search_MaterialsNumber(string key)
        {
            string sql = @"select id,name,number,type,remark
                        from materials_number where name like '%" + key + "%'";
            return op.Query(sql);
        }

    }
}
